﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FundMarket.aspx.cs" Inherits="FundMarket" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <script type="text/javascript" language="javascript">

         function Call1() {
             $("#divMessagePanel").html("");

             var row = '<table>';
             var url = "http://localhost:9162/FundMarketService.svc/GetFoundMarket";
             row += '<td>标准代码</td><td>基金简称</td><td>投资类型</td><td>单位净值</td>';
             $.getJSON(url, null, function(json) {
                 $.each(json, function(i) {
                     row += '<tr>';
                     row += '<td>' + json[i].bzdm + '</td><td><a href="FundDetails.aspx?jjdm=' + json[i].jjdm + '" target ="_blank">' + json[i].jjjc + '</a></td><td>' + json[i].tzdx + '</td><td>' + json[i].dwjz + '</td>';
                     row += '</tr>';
                 });
                 alert('');
                 row += '</table>';
                 $('#divMessagePanel').html(row);
             }
            );
         }
     
        function Call() {
            $("#divMessagePanel").html("");
            var formativeData = { "BoolValue": 1, "StringValue": "李四" };
            var jsonStr = '{"composite":' + json2string(formativeData) + "}";

            $.ajax({
                type: "get",
                url: "http://localhost:9162/FundMarketService.svc/GetFoundMarket",
                contentType: "application/json;charset=utf-8",
                data: null,
                success: function(data) {
                    //alert(data);
                    var a = data;// eval("(" + data + ")");
                    var d = ChangeDateFormat(a[0].maxfsrq);

                    alert(d);
                    $('#divMessagePanel').html("ok");
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    $("#divMessagePanel").html("error");
                },
                cache: false
            });
        }

        function ChangeDateFormat(cellval) {
            var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            return date.getFullYear() + "-" + month + "-" + currentDate;
        }
       
        //可选，采用 json2.js
        function json2string(strObject) {
            var c, i, l, s = '', v, p;

            switch (typeof strObject) {
                case 'object':
                    if (strObject) {
                        if (strObject.length && typeof strObject.length == 'number') {
                            for (i = 0; i < strObject.length; ++i) {
                                v = json2string(strObject[i]);
                                if (s) {
                                    s += ',';
                                }
                                s += v;
                            }
                            return '[' + s + ']';
                        } else if (typeof strObject.toString != 'undefined') {
                            for (i in strObject) {
                                v = strObject[i];
                                if (typeof v != 'undefined' && typeof v != 'function') {
                                    v = json2string(v);
                                    if (s) {
                                        s += ',';
                                    }
                                    s += json2string(i) + ':' + v;
                                }
                            }
                            return '{' + s + '}';
                        }
                    }
                    return 'null';
                case 'number':
                    return isFinite(strObject) ? String(strObject) : 'null';
                case 'string':
                    l = strObject.length;
                    s = '"';
                    for (i = 0; i < l; i += 1) {
                        c = strObject.charAt(i);
                        if (c >= ' ') {
                            if (c == '\\' || c == '"') {
                                s += '\\';
                            }
                            s += c;
                        } else {
                            switch (c) {
                                case '\b':
                                    s += '\\b';
                                    break;
                                case '\f':
                                    s += '\\f';
                                    break;
                                case '\n':
                                    s += '\\n';
                                    break;
                                case '\r':
                                    s += '\\r';
                                    break;
                                case '\t':
                                    s += '\\t';
                                    break;
                                default:
                                    c = c.charCodeAt();
                                    s += '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
                            }
                        }
                    }
                    return s + '"';
                case 'boolean':
                    return String(strObject);
                default:
                    return 'null';
            }
        }    　
    </script>
</head>
<body>
    <form id="form1" runat="server">
     <script src="Script/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <div>
    
    </div>
    <div id="divMessagePanel">
        <input type="button" value="Call" onclick="Call()" />
        <input type="button" value="CallFundList" onclick="Call1()" />
       
    </div>
    </form>
</body>
</html>
